home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 4.9 KB | 152 lines |
- import java.awt.*;
-
- /**
- * The Progress panel that displays progress information and a progress bar
- *
- * @author Levi Brown
- * @author Michael Hopkins
- * @author Apple Computer, Inc.
- * @version 1.0 10/21/1999
- *
- * Copyright: © Copyright 1999 Apple Computer, Inc. All rights reserved.
- *
- * Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
- * ("Apple") in consideration of your agreement to the following terms, and your
- * use, installation, modification or redistribution of this Apple software
- * constitutes acceptance of these terms. If you do not agree with these terms,
- * please do not use, install, modify or redistribute this Apple software.
- *
- * In consideration of your agreement to abide by the following terms, and subject
- * to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
- * copyrights in this original Apple software (the "Apple Software"), to use,
- * reproduce, modify and redistribute the Apple Software, with or without
- * modifications, in source and/or binary forms; provided that if you redistribute
- * the Apple Software in its entirety and without modifications, you must retain
- * this notice and the following text and disclaimers in all such redistributions of
- * the Apple Software. Neither the name, trademarks, service marks or logos of
- * Apple Computer, Inc. may be used to endorse or promote products derived from the
- * Apple Software without specific prior written permission from Apple. Except as
- * expressly stated in this notice, no other rights or licenses, express or implied,
- * are granted by Apple herein, including but not limited to any patent rights that
- * may be infringed by your derivative works or by other works in which the Apple
- * Software may be incorporated.
- *
- * The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
- * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
- * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
- * COMBINATION WITH YOUR PRODUCTS.
- *
- * IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
- * OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
- * (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- public class Progress extends Panel
- {
- public Progress(int max)
- {
- this.max = (double)max;
- size = new Dimension(300,81);
- index = 0;
-
- GridBagLayout gridBagLayout;
- gridBagLayout = new GridBagLayout();
- setLayout(gridBagLayout);
- setVisible(false);
- setSize(size);
-
- Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize();
- Dimension dSize = getSize();
- setLocation((sSize.width - dSize.width) >> 1, (int)(0.33333333 * sSize.height));
-
- setBackground(new Color(-1644826));
-
- paramLabel = new java.awt.Label("Gathering the animals...");
- GridBagConstraints gbc;
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 1;
- gbc.gridwidth = 1;
- gbc.weightx = 0.5;
- gbc.anchor = GridBagConstraints.NORTHWEST;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.insets = new Insets(10,10,0,10);
- ((GridBagLayout)getLayout()).setConstraints(paramLabel, gbc);
- add(paramLabel);
-
- progressBar1 = new ProgressBar();
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 2;
- gbc.gridwidth = 1;
- gbc.anchor = GridBagConstraints.CENTER;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.insets = new Insets(10,10,10,10);
- ((GridBagLayout)getLayout()).setConstraints(progressBar1, gbc);
- add(progressBar1);
- }
-
- public void updateProgress(String text)
- {
- paramLabel.setText(text);
- updateProgress();
- }
-
- public void updateProgress()
- {
- index++;
-
- try
- {
- progressBar1.setPercent(index/max);
- }
- catch (IllegalArgumentException exc) { }
-
- repaint();
- }
-
- public void paint(Graphics g)
- {
- super.paint(g);
-
- Dimension s = getSize();
- int width = s.width - 1;
- int height = s.height - 1;
-
- for (int i = 0; i < 2; ++i)
- {
- width -= i;
- height -= i;
-
- g.setColor(Color.white);
- g.drawLine(i, i, width, i);
- g.drawLine(i, i, i, height);
-
- g.setColor(Color.gray);
- g.drawLine(i, height, width, height);
- g.drawLine(width, i, width, height);
- }
- }
-
- public void update(Graphics g)
- {
- paint(g);
- }
-
- public Dimension getPreferredSize()
- {
- return size;
- }
-
- protected int index;
- protected double max;
- protected Label paramLabel;
- protected Label fileLabel;
- protected ProgressBar progressBar1;
- protected Dimension size;
- }